package com.example.himalayaproject.find.recommend.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.himalayaproject.R;
import com.example.himalayaproject.find.recommend.RecommendWebActivity.RecommendActivity;
import com.example.himalayaproject.find.recommend.bean.ListEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/11.
 */

public class HotApapter extends RecyclerView.Adapter<HotApapter.ViewHold> implements View.OnClickListener {
    private List<ListEntity> list;
    private Context context;
    private Intent intent;

    public HotApapter(List<ListEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {

        View rootView = LayoutInflater.from(context).inflate(R.layout.recommend_itembase, parent, false);
        return new ViewHold(rootView);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, int position) {
        Picasso.with(context).load(list.get(position).getCoverSmall()).into(holder.img);
        holder.text1.setText(list.get(position).getTrackTitle());
        holder.text2.setText(list.get(position).getTitle());
        holder.img2.setVisibility(View.VISIBLE);
        holder.layout.setOnClickListener(this);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onClick(View v) {
        int position = ((RecyclerView) v.getParent()).getChildAdapterPosition(v);
//        Intent intent = new Intent(context, RecommendActivity.class);
//        intent.putExtra("url", list.get(position).getAlbumId());
//        context.startActivity(intent);
        intent = new Intent(context, RecommendActivity.class);
        context.startActivity(intent);
        Toast.makeText(context, "点击了" + list.get(position).getAlbumId() + "位置" + position, Toast.LENGTH_SHORT).show();
    }

    public static class ViewHold extends RecyclerView.ViewHolder {
        private ImageView img;
        private TextView text1;
        private TextView text2;
        private ImageView img2;
        private LinearLayout layout;

        public ViewHold(View itemView) {
            super(itemView);
            img = ((ImageView) itemView.findViewById(R.id.item03_img));
            text1 = ((TextView) itemView.findViewById(R.id.item03_text1));
            text2 = ((TextView) itemView.findViewById(R.id.item03_text2));
            img2 = ((ImageView) itemView.findViewById(R.id.item03_img2));
            layout = ((LinearLayout) itemView.findViewById(R.id.recommend_baselayout));
        }
    }
}
